<?php

/**
 * @author		Chris Hazekamp
 * @copyright	2009
 * @access		internal
 * @filesource	core.php
 */

// Security stuff
if (!defined('PUBLIC_HTML'))
{
	exit;
}

// Debug Mode
define('DEBUG_MODE', true);
if (!defined('DEBUG_MODE'))
{
	error_reporting(E_ALL ^ E_NOTICE);
}
else
{
	//error_reporting(E_ALL ^ E_DEPRECATED);
	error_reporting(E_ALL);
}

// To correct the idiot who may have turned it on
if (@ini_get('register_globals') == 'On')
{
	@ini_set('register_globals', 'Off');
}

// Check for PHP version for work with Classes

if (phpversion() >= '6.0.0')
{
	$php_version = 'php6';
}
elseif (phpversion() >= '5.0.0')
{
	$php_version = 'php5';
}
elseif (phpversion() >= '4.0.0')
{
	$php_version = 'php4';
}
else
{
	$php_version = 'php3';
}

// Define the file paths
define('PATH_PHP',		'includes/');
define('PATH_CONTENTS',	'content/');
define('PATH_HTML',		'output/cfh/');
define('PATH_CMS',		'cms/');
define('PATH_CMS_HTML',	'cms/output/');
define('PATH_MODULES',	'modules/');

// Define the extensions
define('EXT_PHP',	'.php');
define('EXT_HTML',	'.html');

// Get the database configurations
require('dbcfgs'.EXT_PHP);

// Get important files
$fti = array('defs', 'functions', 'exceptions', 'db', 'db2', 'image', 'string', 'javascript', 'file', 'user', 'config', 'validator', 'language', 'template2', 'cache', 'content', 'mobile');
foreach ($fti as $key)
{
	include(PATH_PHP . $key . EXT_PHP);
}

// Classes

// First the database class, which automaticly connects to a database
try
{
	$db 		= new Database($db_data);
}
catch (ErrorHandler $e)
{
	$e->print_error();
}

// New Database
$database 	= new DatabasePDO();

// Then the Config data that is obtained from the database
$config		= new Config();

// Next get the user class. Cookie names are defined in the config table
$user		= new User($config->get('cookie_user_id'), $config->get('cookie_user_pass'));

// Get the class for string manipulation
$string		= new String();

// Get the image class for easier image manipulation
$image		= new Image();

// Get the File class for easier file management
$file		= new FileManager();

// Get the Javascript class
$javascript	= new Javascript();

// Get the Validator class
$validator	= new Validator();

// Get the Language class
$language	= new Language('en', 'en');

// Get the Mobile class
$mobile		= new Mobile_Detect();

// Get the Template class
$tpl		= new Template();

// Get the Cache class
$cache		= new Cache(CACHE_FOLDER);

// Get the Exception Class
$error		= new ErrorHandler();

// Get the Content Class
$content	= new Content();

// Make htaccess
if (!file_exists('.htaccess'))
{
	$htaccess_content = 
	'
	RewriteEngine On
	RewriteRule !\.(gif|jpg|png|css|js|htc|php|htm|html)$ index.php
	Options -Indexes
	errorDocument 403 403
	errorDocument 404 404
	errorDocument 500 500
	
	<Files core.php>
	order deny,allow
	deny from all
	</Files>
	
	<Files dbcfgs.php>
	order deny,allow
	deny from all
	</Files> 
	';
	
	$create_htaccess = $file->create('.htaccess', $htaccess_content);
	if ($create_htaccess)
	{
		define('URL_REWRITE', true);
	}
	else
	{
		define('URL_REWRITE', false);
	}
}
else
{
	define('URL_REWRITE', true);
}

// Website Paths
//$domain_protocol = (preg_match('/(http:\/\/|https:\/\/)/', $config->get('domain_protocol'))) ? $config->get('domain_protocol') : 'http://';

$main_path      = $config->get('domain_protocol') . $config->get('site_domain') . $config->get('site_path');
$public_path    = (URL_REWRITE == true) ? $main_path.'index/' : $main_path.'index'.EXT_PHP;
$admin_path     = $main_path.'cms'.EXT_PHP;

// Source paths
$media_path     = $main_path.'media/';
$image_path     = $main_path.'output/cfh/imgs/';

// URL Rewrite var
$url_path	= $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$static_path= $config->get('site_domain') . $config->get('site_path');
if (URL_REWRITE == true)
{
	$url_params = explode('/', $url_path);
	$url_offset = preg_match_all('/\//', $static_path, $url_offset);
}
else
{
	$url_params = array();
	$url_offset = 0;
}

$hallo = 'hoi';

?>